package com.study.juc;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;
import java.util.concurrent.TimeUnit;

public class FutureDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        FutureTask<String> future = new FutureTask<>(new MyFuture());
        Thread t = new Thread(future, "name");
        t.start();
        while (true) {
            if (future.isDone()) {
                String s = future.get();
                System.out.println("s = " + s);
                break;
            }else {
                System.out.println(" 处理中 ");
            }
        }
        System.out.println("main thread  --------- ");
    }
}

class MyFuture implements Callable<String> {
    @Override
    public String call() throws Exception {
        TimeUnit.SECONDS.sleep(3);
        System.out.println(" my future");
        return " my future";
    }
}
